<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">



  
  
    
    
  <script src="/dxl/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/dxl/lib/pace/pace-theme-minimal.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/dxl/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/dxl/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/dxl/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/dxl/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/dxl/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/dxl/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/dxl/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="git,">










<meta name="description" content="一、git工作流程​    使用git就是将本地文件（工作目录workspace）的文件，添加到暂存区（stage）,然后提交到本地仓库（repository），最终可以协同开发，推送到远程仓库（remote）     二、基本操作2.1建立git仓库、1、git版本库 ​    git版本库，也叫做git仓库（repository），也就是一个文件夹。 ​    这个目录的所有内容被git软件管">
<meta name="keywords" content="git">
<meta property="og:type" content="article">
<meta property="og:title" content="02git基础命令操作">
<meta property="og:url" content="http://yoursite.com/2019/09/04/【git】02git基础命令操作/index.html">
<meta property="og:site_name" content="我的快乐时光">
<meta property="og:description" content="一、git工作流程​    使用git就是将本地文件（工作目录workspace）的文件，添加到暂存区（stage）,然后提交到本地仓库（repository），最终可以协同开发，推送到远程仓库（remote）     二、基本操作2.1建立git仓库、1、git版本库 ​    git版本库，也叫做git仓库（repository），也就是一个文件夹。 ​    这个目录的所有内容被git软件管">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://yoursite.com/2019/09/04/【git】02git基础命令操作/assets%5C1563098880024.png">
<meta property="og:image" content="http://yoursite.com/2019/09/04/【git】02git基础命令操作/assets%5C1563100210029.png">
<meta property="og:image" content="http://yoursite.com/2019/09/04/【git】02git基础命令操作/assets%5C1563104123260.png">
<meta property="og:image" content="http://yoursite.com/2019/09/04/【git】02git基础命令操作/assets%5C1563103676924.png">
<meta property="og:image" content="http://yoursite.com/images/1.jpg">
<meta property="og:updated_time" content="2019-09-10T09:46:15.298Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="02git基础命令操作">
<meta name="twitter:description" content="一、git工作流程​    使用git就是将本地文件（工作目录workspace）的文件，添加到暂存区（stage）,然后提交到本地仓库（repository），最终可以协同开发，推送到远程仓库（remote）     二、基本操作2.1建立git仓库、1、git版本库 ​    git版本库，也叫做git仓库（repository），也就是一个文件夹。 ​    这个目录的所有内容被git软件管">
<meta name="twitter:image" content="http://yoursite.com/2019/09/04/【git】02git基础命令操作/assets%5C1563098880024.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/dxl/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":true,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2019/09/04/【git】02git基础命令操作/">





  <title>02git基础命令操作 | 我的快乐时光</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/dxl/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">我的快乐时光</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/dxl/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/dxl/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/dxl/2019/09/04/【git】02git基础命令操作/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content>
      <meta itemprop="description" content>
      <meta itemprop="image" content="/dxl/images/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="我的快乐时光">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">02git基础命令操作</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-09-04T22:10:05+08:00">
                2019-09-04
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/dxl/categories/git/" itemprop="url" rel="index">
                    <span itemprop="name">git</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/dxl/2019/09/04/【git】02git基础命令操作/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count valine-comment-count" data-xid="/dxl/2019/09/04/【git】02git基础命令操作/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv">本文总阅读量
            <span class="busuanzi-value" id="busuanzi_value_page_pv"></span>次
            </span>
          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="一、git工作流程"><a href="#一、git工作流程" class="headerlink" title="一、git工作流程"></a>一、git工作流程</h2><p>​    使用git就是将本地文件（工作目录workspace）的文件，添加到暂存区（stage）,然后提交到本地仓库（repository），最终可以协同开发，推送到远程仓库（remote）    <img src="assets%5C1563098880024.png" alt="1563098880024"></p>
<h3 id="二、基本操作"><a href="#二、基本操作" class="headerlink" title="二、基本操作"></a>二、基本操作</h3><h3 id="2-1建立git仓库、"><a href="#2-1建立git仓库、" class="headerlink" title="2.1建立git仓库、"></a>2.1建立git仓库、</h3><p>1、git版本库</p>
<p>​    git版本库，也叫做git仓库（repository），也就是一个文件夹。</p>
<p>​    这个目录的所有内容被git软件管理，所有的修改，删除，git都会跟踪记录，便于可以跟踪历史记录，以后可以还原文件。</p>
<p>2、根据已有的项目纳入git管理</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">cd mysite    <span class="comment"># mysite项目所在代码</span></span><br><span class="line">git init        <span class="comment">#初始化git仓库</span></span><br><span class="line"></span><br><span class="line">git init命令会创建一个.git隐藏子目录，这个目录包含初始化git仓库所有的核心文件。</span><br><span class="line">此步仅仅是初始化，此时项目里的代码还没有被git跟踪，因此还需要git add对项目文件跟踪，然后git commit提交到本地仓库</span><br></pre></td></tr></table></figure>

<p>3、新建一个项目、直接用git管理</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd 某个文件夹</span><br><span class="line">git init mysite      <span class="comment">#此步会在当前路径创建mysite文件夹，mysite文件夹中包含了.git的初始化文件夹，所有配置</span></span><br></pre></td></tr></table></figure>

<p>4、获取远程仓库代码</p>
<p>​     如果你想获取github上的代码，或者你公司gitlab私有仓库的代码，可以使用git clone命令，下载克隆远程仓库的代码。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git clone https://github.com/django/django.git</span><br></pre></td></tr></table></figure>

<p>5、git文件夹解析</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">[root@pyyuc ~/git_learning/mysite 11:08:19]#tree .git</span><br><span class="line">.git</span><br><span class="line">├── branches</span><br><span class="line">├── config　　　　这个项目独有的配置</span><br><span class="line">├── description</span><br><span class="line">├── HEAD　　　　head文件指示目前被检出的分支</span><br><span class="line">├── hooks　　hooks目录包含服务端和客户端的钩子脚本 hook scripts</span><br><span class="line">│   ├── applypatch-msg.sample</span><br><span class="line">│   ├── commit-msg.sample</span><br><span class="line">│   ├── post-update.sample</span><br><span class="line">│   ├── pre-applypatch.sample</span><br><span class="line">│   ├── pre-commit.sample</span><br><span class="line">│   ├── prepare-commit-msg.sample</span><br><span class="line">│   ├── pre-push.sample</span><br><span class="line">│   ├── pre-rebase.sample</span><br><span class="line">│   └── update.sample</span><br><span class="line">├── index  index文件保存暂存区的信息，只有git add之后才会生成，默认还没有这个文件</span><br><span class="line">├── info　　　　info目录是全局性排除文件，用于放置不想被记录在.gitignore文件中的忽略模式（ignored patterns）</span><br><span class="line">│   └── exclude</span><br><span class="line">├── objects　　存储所有数据内容</span><br><span class="line">│   ├── info</span><br><span class="line">│   └── pack</span><br><span class="line">└── refs　　refs目录存储指向数据（分支）的提交对象的指针</span><br><span class="line">    ├── heads</span><br><span class="line">    └── tags</span><br></pre></td></tr></table></figure>

<h3 id="2-2纪录更新到本地参考库"><a href="#2-2纪录更新到本地参考库" class="headerlink" title="2.2纪录更新到本地参考库"></a>2.2纪录更新到本地参考库</h3><p>​    1、git仓库</p>
<p>​    本地文件夹未初始化，git是不认识的本地文件git init后，就成了git仓库。</p>
<p>​    2、文件的状态</p>
<p>​    在工作文件夹的每一个文件，只有两种状态，一个是未跟踪，一个是已跟踪。已跟踪已跟踪的指的是已经被纳入git版本管理的文件，在git快照中有他的记录未跟踪的是这个文件既不在git快照中，也不在暂存区</p>
<p>​    git init初始化时的工作文件夹，都属于已跟踪了，后续的编辑操作都会标记为，已修改文件，因此需要将修改后的文件，加入暂存区，然后提交暂存区的文件。</p>
<p><img src="assets%5C1563100210029.png" alt="1563100210029"></p>
<h4 id="2-3检查文件状态"><a href="#2-3检查文件状态" class="headerlink" title="2.3检查文件状态"></a>2.3检查文件状态</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git status</span><br></pre></td></tr></table></figure>

<h4 id="2-4git生命周期演练"><a href="#2-4git生命周期演练" class="headerlink" title="2.4git生命周期演练"></a>2.4git生命周期演练</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">git init mysite                          初始化git仓库</span><br><span class="line"></span><br><span class="line">git status                                 查看git状态</span><br><span class="line"></span><br><span class="line">echo <span class="string">'print("挣了一个亿")'</span> &gt; main.py        新建一个代码文件，此时是未被git跟踪的</span><br><span class="line"></span><br><span class="line">git status                                查看状态</span><br><span class="line"></span><br><span class="line">git add main.py　　开始跟踪main.py文件</span><br><span class="line"></span><br><span class="line">git status 　　此时再看已经被跟踪，现在已是可以被提交的状态,此时处于暂存区</span><br><span class="line"></span><br><span class="line">git commit -m <span class="string">"echo main.py"</span>  告诉git，把暂存区的main.py提交到本地仓库</span><br><span class="line"></span><br><span class="line">git log 　　　　查看刚才的commit记录</span><br></pre></td></tr></table></figure>

<h3 id="2-5文件的改名"><a href="#2-5文件的改名" class="headerlink" title="2.5文件的改名"></a>2.5文件的改名</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">first:</span><br><span class="line">mv main.py  mymain.py <span class="comment">#直接mv的操作，会被git记录为两个形容，一、删除原有文件、二、新建了mymain.py文件</span></span><br><span class="line">此时新文件还未被跟踪，需要git add , git commit</span><br><span class="line">原本的main.py还需要从暂存区删除</span><br><span class="line">git add mumain.py</span><br><span class="line">git rmmain.py</span><br><span class="line">git commit -m <span class="string">"mv mymain.py"</span></span><br><span class="line"></span><br><span class="line">second:</span><br><span class="line">git mv main.py mymain.py 　</span><br><span class="line">git commit -m <span class="string">"mv mymain.py"</span></span><br></pre></td></tr></table></figure>

<h3 id="2-6查看git版本历史"><a href="#2-6查看git版本历史" class="headerlink" title="2.6查看git版本历史"></a>2.6查看git版本历史</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">git log --oneline    一行显示git记录</span><br><span class="line">git log --oneline  --all  一行显示所有分支git记录</span><br><span class="line">git log --oneline --all -4 --graph 显示所有分支的版本演进的最近4条</span><br><span class="line">git log -4  显示最近4条记录</span><br><span class="line">git log --all     显示所有分支的commit信息</span><br><span class="line">git branch -v 查看分支信息</span><br><span class="line">git help --web log 以web界面显示log的参数</span><br></pre></td></tr></table></figure>

<h3 id="2-7git版本的回退"><a href="#2-7git版本的回退" class="headerlink" title="2.7git版本的回退"></a>2.7git版本的回退</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">git log可以查看历史版本记录</span><br><span class="line">git reset --hard命令可以回退版本</span><br><span class="line">git reset --hard HEAD^ 回退到上个版本 改变的时指针的指向</span><br><span class="line">HEAD表示当前版版本</span><br><span class="line">HEAD^表示上个版本</span><br><span class="line">HEAD^^上上个版本</span><br><span class="line"></span><br><span class="line">也可以直接git reset --hard 版本id号</span><br></pre></td></tr></table></figure>

<h3 id="2-8git-reflog"><a href="#2-8git-reflog" class="headerlink" title="2.8git  reflog"></a>2.8git  reflog</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">git reflog <span class="comment"># 查看所有的提交记录</span></span><br><span class="line"><span class="string">"""</span></span><br><span class="line"><span class="string">80f9496 HEAD@&#123;1&#125;: reset: moving to HEAD^</span></span><br><span class="line"><span class="string">b7a8740 (HEAD -&gt; master) HEAD@&#123;2&#125;: commit: echo 123</span></span><br><span class="line"><span class="string">80f9496 HEAD@&#123;3&#125;: commit: echo my.txt</span></span><br><span class="line"><span class="string">bf5879e HEAD@&#123;4&#125;: commit (initial): echo my.txt</span></span><br><span class="line"><span class="string">"""</span></span><br></pre></td></tr></table></figure>

<h3 id="2-9git工作区相关命令"><a href="#2-9git工作区相关命令" class="headerlink" title="2.9git工作区相关命令"></a>2.9git工作区相关命令</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">pwd</span><br><span class="line">ls</span><br></pre></td></tr></table></figure>

<h3 id="2-10git仓库"><a href="#2-10git仓库" class="headerlink" title="2.10git仓库"></a>2.10git仓库</h3><p>​    工作区里有一个.git隐藏文件夹，就是git的本地仓库</p>
<p>​    .git文件夹里有一个index文件，就是git的暂存区，也叫做stage</p>
<p>​    .git文件夹里的HEAD文件就是git的一个指针</p>
<p>​    原理图</p>
<p><img src="assets%5C1563104123260.png" alt="1563104123260"></p>
<h3 id="2-11工作区的修改纪律"><a href="#2-11工作区的修改纪律" class="headerlink" title="2.11工作区的修改纪律"></a>2.11工作区的修改纪律</h3><p>1、撤销修改记录，<strong>只能在未提交到暂存区之前</strong> </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git status</span><br><span class="line">git checkout -- my.txt  放弃工作区的修改操作</span><br></pre></td></tr></table></figure>

<p>2、如果你修改了文件，还添加到了暂存区 git add，那么只能撤销暂存区的操作，再撤销修改记录</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git status    </span><br><span class="line">git reset HEAD readme.txt  撤销暂存区的修改，unstage操作</span><br><span class="line">git checkout -- readme.txt</span><br></pre></td></tr></table></figure>

<h3 id="2-12删除文件与恢复文件"><a href="#2-12删除文件与恢复文件" class="headerlink" title="2.12删除文件与恢复文件"></a>2.12删除文件与恢复文件</h3><p>1、文件的删除</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">如果你直接在工作区删除文件，动作会被git记录</span><br><span class="line">rm -rf my.txt    删除了工作区的文件，git仓库还有记录</span><br><span class="line">git status    查看状态，可以检测到my.txt被删除</span><br><span class="line"></span><br><span class="line">如果确认文件无用，可以commit到git仓库</span><br><span class="line">git rm &quot;my.txt&quot;</span><br><span class="line">git commit -m &quot;remove my.txt&quot;</span><br></pre></td></tr></table></figure>

<p>2、文件的恢复</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">rm -rf my.txt</span><br><span class="line">git checkout -- my.txt</span><br></pre></td></tr></table></figure>

<h3 id="2-13git-stash"><a href="#2-13git-stash" class="headerlink" title="2.13git stash"></a>2.13git stash</h3><p>1、相关命令</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">git stash <span class="comment">#保存暂存区，工作区进度，工作区有变动</span></span><br><span class="line">git stash list <span class="comment">#查看stash保存的列表以及id</span></span><br><span class="line">git stash pop  <span class="comment">#恢复最新的stash进度到工作区</span></span><br><span class="line">git stash pop stash_id  <span class="comment">#恢复指定的stash进度</span></span><br><span class="line">git stash clear <span class="comment">#清空所有存储的stash进度</span></span><br><span class="line">git stash drop stash_id  <span class="comment">#删除一个存储的stash进度</span></span><br><span class="line">git stash apply  <span class="comment">#恢复stash存储，且不删除stash list中的记录</span></span><br><span class="line">git stash <span class="comment">#每次只做一个就可以，容易发生混乱</span></span><br></pre></td></tr></table></figure>

<p>2、git stash 的实际用法</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>、git status <span class="comment">#查看当前仓库的状态</span></span><br><span class="line"><span class="number">2</span>、touch xx.py <span class="comment">#创建一个文件</span></span><br><span class="line"><span class="number">3</span>、git add xx.py <span class="comment">#跟踪一个文件</span></span><br><span class="line"><span class="number">4</span>、git status <span class="comment">#查看当前仓库的状态</span></span><br><span class="line"><span class="number">5</span>、git stash <span class="comment"># 将文件放入到暂存区</span></span><br><span class="line"><span class="number">6</span>、ls <span class="comment">#看不到 xx.py</span></span><br><span class="line"><span class="number">7</span>、git stash list <span class="comment">#查看stash列表</span></span><br><span class="line"><span class="number">8</span>、git stash apply <span class="comment">#恢复 xx.py</span></span><br><span class="line"><span class="number">9</span>、 git stash dro <span class="comment">#移除stash</span></span><br></pre></td></tr></table></figure>

<p>3、图解</p>
<p><img src="assets%5C1563103676924.png" alt="1563103676924"></p>
<h3 id="2-14-diff"><a href="#2-14-diff" class="headerlink" title="2.14 diff"></a>2.14 diff</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git diff  <span class="comment"># 对比本地仓库和工作区的区别 git add之前执行 diff 会看到差别</span></span><br><span class="line">git diff --cached <span class="comment">#对比的本地仓库和缓存区的区别,git add 之后执行会看到差别</span></span><br></pre></td></tr></table></figure>

<h2 id="三、远程仓库"><a href="#三、远程仓库" class="headerlink" title="三、远程仓库"></a>三、远程仓库</h2><h2 id="3-1相关命令"><a href="#3-1相关命令" class="headerlink" title="3.1相关命令"></a>3.1相关命令</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">git config --global -l </span><br><span class="line">git config --global --unset user.email</span><br><span class="line">git pull origin  master</span><br><span class="line">git clone https://url.git  只有一个master分支</span><br><span class="line">git checkout -b name origin/name </span><br><span class="line">git push origin --delete name  删除远程仓库的分支</span><br><span class="line">git pull = git fetch + git merge</span><br><span class="line">git fetch 将文件拉取下来，但是不会合并</span><br><span class="line">git checkout -b dev origin/dev = git branch dev origin/dev + git checkout dev</span><br><span class="line">#以远程仓库的dev分支做母版创建一个dev分支’</span><br><span class="line"></span><br><span class="line">git pull origin name #将远程仓库的文件拉取到本地</span><br></pre></td></tr></table></figure>

<h3 id="四、忽略文件"><a href="#四、忽略文件" class="headerlink" title="四、忽略文件"></a>四、忽略文件</h3><p>.gitignore</p>
<h3 id="五、tag-标签"><a href="#五、tag-标签" class="headerlink" title="五、tag 标签"></a>五、tag 标签</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">git tag 查看标</span><br><span class="line">git show 查看标签的详细信息</span><br><span class="line">git tag -a v1<span class="number">.0</span> -m <span class="string">"信息"</span>  对当前位置打标签</span><br><span class="line">git tag -a v1<span class="number">.0</span> -m <span class="string">"信息"</span>  hash值 对之前的位置打标签</span><br><span class="line">git tag -d  name 删除标签</span><br><span class="line">git push origin --tags 将本地的tag推送到远程仓库</span><br><span class="line">git push origin   :refs/tags/name 删除远程的tags</span><br><span class="line">解析：</span><br><span class="line"><span class="number">1.1</span> <span class="number">-1.2</span>  <span class="comment">#新增重要的功能 里程碑</span></span><br><span class="line"><span class="number">1.11</span> <span class="number">-1.12</span> <span class="comment"># bug修复以后</span></span><br></pre></td></tr></table></figure>

<p><img src="/images/1.jpg" alt></p>

      
    </div>
    
    
    

    

    

    
      <div>
        <ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者：</strong>
    
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="http://yoursite.com/2019/09/04/【git】02git基础命令操作/" title="02git基础命令操作">http://yoursite.com/2019/09/04/【git】02git基础命令操作/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>
    本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/3.0/" rel="external nofollow" target="_blank">CC BY-NC-SA 3.0</a> 许可协议。转载请注明出处！
  </li>
</ul>

      </div>
    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/dxl/tags/git/" rel="tag"># git</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/dxl/2019/09/04/【git】01git 介绍及安装/" rel="next" title="01git介绍及安装">
                <i class="fa fa-chevron-left"></i> 01git介绍及安装
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/dxl/2019/09/04/【git】03git分支 /" rel="prev" title="03git分支操作">
                03git分支操作 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
    </div>
  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/dxl/images/avatar.png" alt>
            
              <p class="site-author-name" itemprop="name"></p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/dxl/archives">
              
                  <span class="site-state-item-count">43</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/dxl/categories/index.html">
                  <span class="site-state-item-count">6</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/dxl/tags/index.html">
                  <span class="site-state-item-count">6</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-inline">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-sign-out"></i>
                我的友链
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="tencent://message/?Menu=yes&uin=1258517737&Site=QQ%E6%9E%81%E5%AE%A2&Service=300&sigT=45a1e5847943b64c6ff3990f8a9e644d2b31356cb0b4ac6b24663a3c8dd0f8aa12a595b1714f9d45/" title="申请坑位" target="_blank">申请坑位</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#一、git工作流程"><span class="nav-number">1.</span> <span class="nav-text">一、git工作流程</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#二、基本操作"><span class="nav-number">1.1.</span> <span class="nav-text">二、基本操作</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1建立git仓库、"><span class="nav-number">1.2.</span> <span class="nav-text">2.1建立git仓库、</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2纪录更新到本地参考库"><span class="nav-number">1.3.</span> <span class="nav-text">2.2纪录更新到本地参考库</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-3检查文件状态"><span class="nav-number">1.3.1.</span> <span class="nav-text">2.3检查文件状态</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-4git生命周期演练"><span class="nav-number">1.3.2.</span> <span class="nav-text">2.4git生命周期演练</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-5文件的改名"><span class="nav-number">1.4.</span> <span class="nav-text">2.5文件的改名</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-6查看git版本历史"><span class="nav-number">1.5.</span> <span class="nav-text">2.6查看git版本历史</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-7git版本的回退"><span class="nav-number">1.6.</span> <span class="nav-text">2.7git版本的回退</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-8git-reflog"><span class="nav-number">1.7.</span> <span class="nav-text">2.8git  reflog</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-9git工作区相关命令"><span class="nav-number">1.8.</span> <span class="nav-text">2.9git工作区相关命令</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-10git仓库"><span class="nav-number">1.9.</span> <span class="nav-text">2.10git仓库</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-11工作区的修改纪律"><span class="nav-number">1.10.</span> <span class="nav-text">2.11工作区的修改纪律</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-12删除文件与恢复文件"><span class="nav-number">1.11.</span> <span class="nav-text">2.12删除文件与恢复文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-13git-stash"><span class="nav-number">1.12.</span> <span class="nav-text">2.13git stash</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-14-diff"><span class="nav-number">1.13.</span> <span class="nav-text">2.14 diff</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#三、远程仓库"><span class="nav-number">2.</span> <span class="nav-text">三、远程仓库</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-1相关命令"><span class="nav-number">3.</span> <span class="nav-text">3.1相关命令</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#四、忽略文件"><span class="nav-number">3.1.</span> <span class="nav-text">四、忽略文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#五、tag-标签"><span class="nav-number">3.2.</span> <span class="nav-text">五、tag 标签</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
            <span id="scrollpercent"><span>0</span>%</span>
          
        </div>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-hand-peace-o"></i>
  </span>
  <span class="author" itemprop="copyrightHolder"></span>

  
</div>









        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      本站访客数
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      人次
    </span>
  

  
    <span class="site-pv">
      本站总访问量
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      次
    </span>
  
</div>








        
      </div>
    </footer>

    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/dxl/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/dxl/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/dxl/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/dxl/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/dxl/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/dxl/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/dxl/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/dxl/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/dxl/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/dxl/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/dxl/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/dxl/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/dxl/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  










  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//unpkg.com/valine/dist/Valine.min.js"></script>
  
  <script type="text/javascript">
    var GUEST = ['nick','mail','link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item=>{
      return GUEST.indexOf(item)>-1;
    });
    new Valine({
        el: '#comments' ,
        verify: false,
        notify: false,
        appId: '13B0JGDuA6ttduN8AQaR8CzF-gzGzoHsz',
        appKey: 'I13r9r5mVgq4jQYpYy6V4gW3',
        placeholder: '欢迎大佬指点~~~',
        avatar:'mm',
        guest_info:guest,
        pageSize:'10' || 10,
    });
  </script>



  





  

  

  

  
  

  

  

  

</body>
</html>
